package com.uetoken.cn.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.uetoken.cn.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author 谢杨
 * @time 2018/8/20 16:37
 * @class 描述:
 */
public class LoadingDialog extends Dialog {
    @BindView(R.id.tv_one)
    TextView mTvOne;
    @BindView(R.id.tv_two)
    TextView mTvTwo;
    @BindView(R.id.tv_three)
    TextView mTvThree;
    @BindView(R.id.tv_four)
    TextView mTvFour;
    @BindView(R.id.tv_five)
    TextView mTvFive;
    private Context mContext;
    private View    lodingView;
    private Animation anim;


    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.loading_dialog);
        this.mContext = context;
        initView();
    }

    private void initView() {
        lodingView = View.inflate(mContext, R.layout.dialog_loading, null);
        setContentView(lodingView);
        ButterKnife.bind(this, lodingView);

        //设置dialog不可取消，不可触碰取消
        setCancelable(false);
        setCanceledOnTouchOutside(false);

        anim = AnimationUtils.loadAnimation(mContext,R.anim.loading_translater_anim_up);


        mTvOne.setAnimation(anim);
        mTvTwo.setAnimation(anim);
        mTvThree.setAnimation(anim);
        mTvFour.setAnimation(anim);
        mTvFive.setAnimation(anim);
    }

    @Override
    public void show() {
        super.show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
             anim.start();
            }
        },500);
    }

    private void startAnim(final Animation anim) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                anim.start();
            }
        },500);
    }

    @Override
    public void dismiss() {
        super.dismiss();

        if (anim!=null){
            anim.cancel();
        }

    }

}
